package io.github.hadyang.leetcode.offer;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringJoiner;
import org.junit.Test;

/** @author haoyang.shi */
public class PrintMinNumber {

  @Test
  public void test() {
    System.out.println(PrintMinNumber(new int[] {3, 32, 321}));
  }

  public String PrintMinNumber(int[] numbers) {
    List<String> nums = new ArrayList<>();
    for (int number : numbers) {
      nums.add(String.valueOf(number));
    }

    nums.sort(Comparator.comparing(s -> s, (o1, o2) -> (o1 + o2).compareTo(o2 + o1)));

    StringJoiner joiner = new StringJoiner("");
    nums.forEach(joiner::add);

    return joiner.toString();
  }
}
